import type {
  OrderCreateParams,
  OrderCreateResult,
  OrderListParams,
  OrderListResult,
  OrderLogisticResult,
  OrderPreResult,
  OrderResult,
} from '@/types/order'
import { http } from '@/utils/http'

/**
 * 获取订单列表
 * @param data
 * @returns
 */
export const getOrderList = (data: OrderListParams) => {
  return http<OrderListResult>({
    url: '/member/order',
    method: 'GET',
    data,
  })
}

/**
 * 填写订单，获取预付订单
 * @returns
 */
export const getMemberOrderPer = () => {
  return http<OrderPreResult>({
    url: '/member/order/pre',
    method: 'GET',
  })
}

/**
 * 获取立即购买预付单
 * @param data
 * @returns
 */
export const getNowBuyPre = (data: { skuId: string; count: number; addressId?: string }) => {
  return http<OrderPreResult>({
    url: '/member/order/pre/now',
    method: 'GET',
    data,
  })
}

/**
 * 创建订单
 * @param data
 * @returns
 */
export const createOrder = (data: OrderCreateParams) => {
  return http<OrderCreateResult>({
    url: '/member/order',
    method: 'POST',
    data,
  })
}

/**
 * 根据订单ID查询详情
 * @param id
 * @returns
 */
export const getOrderById = (id: string) => {
  return http<OrderResult>({
    url: '/member/order/' + id,
    method: 'GET',
  })
}

/**
 * 再次购买
 * @param id
 * @returns
 */
export const getOrderRepurchaseById = (id: string) => {
  return http<OrderResult>({
    url: '/member/order/repurchase/' + id,
    method: 'GET',
  })
}

/**
 * 获取微信支付参数
 * @param data
 * @returns
 */
export const getWxPayMiniParams = (data: { orderId: string }) => {
  return http<WechatMiniprogram.RequestPaymentOption>({
    url: '/pay/wxPay/miniPay',
    method: 'GET',
    data,
  })
}

/**
 * 模拟微信支付
 * @param data
 * @returns
 */
export const getPayMock = (data: { orderId: string }) => {
  return http({
    url: '/pay/mock',
    method: 'GET',
    data,
  })
}

/**
 * 模拟发货
 * @param id
 * @returns
 */
export const mockOrderSend = (id: string) => {
  return http({
    url: `/member/order/consignment/${id}`,
    method: 'GET',
  })
}

/**
 * 确认收货
 * @param id
 * @returns
 */
export const putOrderReceiptById = (id: string) => {
  return http<OrderResult>({
    url: `/member/order/${id}/receipt`,
    method: 'PUT',
  })
}

/**
 * 获取物流信息
 * @param id
 * @returns
 */
export const getOrderLogisticsById = (id: string) => {
  return http<OrderLogisticResult>({
    url: `/member/order/${id}/logistics`,
    method: 'GET',
  })
}

/**
 * 删除订单
 * @param data
 * @returns
 */
export const delOrderByIds = (data: { ids: string[] }) => {
  return http({
    url: '/member/order',
    method: 'DELETE',
    data,
  })
}

/**
 *
 * @param id 订单ID
 * @param data 取消原因
 * @returns
 */
export const cancleOrderById = (id: string, data: { cancelReason: string }) => {
  return http<OrderResult>({
    url: `/member/order/${id}/cancel`,
    method: 'PUT',
    data,
  })
}
